from pprint import pprint
from typing import Callable, List

from utils.StringUtils import get_test_name


class FailedTest:
    def __init__(self, method: Callable, failed_time: str, caused_reason: str):
        self.test_name = get_test_name(method.__name__)
        self.failed_time = failed_time
        self.caused_reason = caused_reason

    def __str__(self):
        return f"{self.test_name}测试失败于{self.failed_time}\t由{self.caused_reason}导致"


class FailedTestLog:

    def __init__(self):
        self.failed_tests: List[FailedTest] = []

    def add_test(self, failed_test):
        self.failed_tests.append(failed_test)

    def print_failed_tests(self) -> None:
        pprint(self.failed_tests)


failed_test_log = FailedTestLog()
